#boof's youtube script
#requires gdata API.
#sux2bu if you don't have it.
import gdata.youtube
import gdata.youtube.service

yt_service = gdata.youtube.service.YouTubeService()
yt_service.developer_key = "AI39si4GqpqLWPTmRyZethVhurKqVgbUBDHJH7hnHTHb4sosC5ZOCICSZ79ha9HpTt6HBYJGv1fMHk3l9Anooj-ys8Ol-Rss6A"

irc = None

def init(bot):
    global irc
    bot.cmd.events['PRIVMSG'].subscribe(privmsg)
    irc = bot
    print "youtube plugin GO!"

def privmsg(sender, args):
    global irc
    msg = args[0]
    if msg.find("v=") != -1:
        print msg.find("v=")
        if msg.find("youtube.com") != -1:
            ylen = msg.find("v=") + 2
            yid = msg[ylen:ylen+11]
            try:
                entry = yt_service.GetYouTubeVideoEntry(video_id=yid)
                irc.privmsg(args[2], entry.media.title.text + " is " + entry.rating.average + "/5.0000000 according to the " + entry.statistics.view_count + " retards that watched it, and will bore us for " + entry.media.duration.seconds + " seconds.")
            except Exception, e:
                irc.privmsg(args[2], "That video is too gay for me to look up.")
                print "Error",e
                pass
    elif msg == "holla":
        quit()
    elif msg == "!assrape":
        if irc.chmgr.get(args[2]).isop(sender.nick):
            try: name = args[0][1]
            except: name = ""
            print name
    elif msg == "\001VERSION\001":
        irc.ctcp_reply(sender.nick, "VERSION %s" % irc.version)
    elif msg == "debug":
        print irc.chmgr.channels

